Last updated: 2023-12-20

Checks: 5 2

Knit directory: ILD_ASE_Xenium/

This reproducible R Markdown analysis was created with workflowr (version 1.7.1). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


The R Markdown file has unstaged changes. To know which version of the R Markdown file created these results, you’ll want to first commit it to the Git repo. If you’re still working on the analysis, you can ignore this warning. When you’re finished, you can run wflow_publish to commit the R Markdown file and build the HTML.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20231206) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Using absolute paths to the files within your workflowr project makes it difficult for you and others to run your code on a different machine. Change the absolute path(s) below to the suggested relative path(s) to make your code more reproducible.

absolute relative
/home/hnatri/ILD_ASE_Xenium/ .
/home/hnatri/ILD_ASE_Xenium/code/colors_themes.R code/colors_themes.R
/home/hnatri/ILD_ASE_Xenium/code/plot_functions.R code/plot_functions.R
/home/hnatri/ILD_ASE_Xenium/code/utilities.R code/utilities.R

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version 83e2df3. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Untracked files:
    Untracked:  analysis/ASE.Rmd
    Untracked:  analysis/endo_mesen_annotations.Rmd
    Untracked:  analysis/panel_overlap.Rmd
    Untracked:  analysis/post_annotation_visualization.Rmd
    Untracked:  data/hLung_XeniumV1.csv

Unstaged changes:
    Modified:   README.md
    Modified:   analysis/Xenium_preprocessing.Rmd
    Modified:   analysis/celltype_annotations.Rmd
    Modified:   analysis/epithelial_annotations.Rmd
    Modified:   analysis/immune_annotations.Rmd
    Modified:   analysis/index.Rmd
    Modified:   code/colors_themes.R
    Modified:   code/utilities.R

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


These are the previous versions of the repository in which changes were made to the R Markdown (analysis/celltype_annotations.Rmd) and HTML (docs/celltype_annotations.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
Rmd 83e2df3 heinin 2023-12-19 Adding lineage level annotations
html 83e2df3 heinin 2023-12-19 Adding lineage level annotations
Rmd b1f446f heinin 2023-12-15 Selecting PCs. Added utilities.

Introduction

Cell type annotations for spatial data.

Packages and environment variables

suppressPackageStartupMessages({library(cli)
                                library(Seurat)
                                library(SeuratObject)
                                library(SeuratDisk)
                                library(tidyverse)
                                library(tibble)
                                library(ggplot2)
                                library(ggpubr)
                                library(ggrepel)
                                library(workflowr)
                                library(googlesheets4)})
Loading Seurat v5 beta version 
To maintain compatibility with previous workflows, new Seurat objects will use the previous object structure by default
To use new Seurat v5 assays: Please run: options(Seurat.object.assay.version = 'v5')
setwd("/home/hnatri/ILD_ASE_Xenium/")
set.seed(9999)
options(ggrepel.max.overlaps = Inf)

# Colors, themes, cell type markers, and plot functions
source("/home/hnatri/ILD_ASE_Xenium/code/colors_themes.R")
✔ Reading from "ILD spatial ASE cell type annotations".
✔ Range ''Epithelial''.
✔ Reading from "ILD spatial ASE cell type annotations".
✔ Range ''Immune''.
✔ Reading from "ILD spatial ASE cell type annotations".
✔ Range ''Mesenchymal''.
✔ Reading from "ILD spatial ASE cell type annotations".
✔ Range ''Endothelial''.
✔ Reading from "ILD spatial ASE cell type annotations".
✔ Range ''All celltypes, annotated, merged''.
source("/home/hnatri/ILD_ASE_Xenium/code/plot_functions.R")
source("/home/hnatri/ILD_ASE_Xenium/code/utilities.R")

Import data

seurat_object <- readRDS("/tgen_labs/banovich/IPF/Spatial_ASE/ILD_ASE_Xenium_processed_npcs20.rds")
DefaultAssay(seurat_object)
[1] "RNA"

Feature expression

# Dimplot of clusters
DimPlot(seurat_object,
        group.by = "leiden_res0.5",
        cols = cluster_col,
        reduction = "umap",
        raster = T,
        label = T) +
  coord_fixed(ratio = 1) +
  NoLegend() +
  theme_minimal()
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`

Version Author Date
83e2df3 heinin 2023-12-19
# Cell type markers
DotPlot(seurat_object,
        features = unique(c(epithelial_features,
                            immune_features,
                            endothelial_features,
                            mesenchymal_features)),
        group.by = "leiden_res0.5",
        cols = c("azure", "tomato3")) +
  coord_flip() +
  theme_minimal()
Warning: The following requested variables were not found (10 out of 126
shown): NKX2-1, RTKN2, NAPSA, PGC, SFTPC, KRT14, KRT5, KRT6A, S100A2, KRT17

Lineage annotations

epi_clusters <- c(9, 7, 8, 9)
imm_clusters <- c(3, 5, 6, 10)
endo_mesen_clusters <- c(1, 2, 4)

Epithelial

Subsetting clusters with any EPCAM expression and reclustering

epithelial <- subset(seurat_object, subset = leiden_res0.5 %in% epi_clusters)

# Saving the object for clustering with scanpy
#saveRDS(epithelial, "/scratch/hnatri/ILD/ILD_spatial_ASE/epithelial.rds")
#epithelial <- readRDS("/scratch/hnatri/ILD/ILD_spatial_ASE/epithelial_clustered.rds")

# Reclustering using Seurat. The function is sourced from /code/utilities.R
epithelial_reclustered <- recluster(epithelial)
# PCs for UMAP: 13
Warning: The default method for RunUMAP has changed from calling Python UMAP via reticulate to the R-native UWOT using the cosine metric
To use Python UMAP via reticulate, set umap.method to 'umap-learn' and metric to 'correlation'
This message will be shown once per session
Found more than one class "dist" in cache; using the first, from namespace 'spam'
Also defined by 'BiocGenerics'
Found more than one class "dist" in cache; using the first, from namespace 'spam'
Also defined by 'BiocGenerics'
#saveRDS(epithelial_reclustered, "/scratch/hnatri/ILD/ILD_spatial_ASE/epithelial_reclustered.rds")

Marker expression

#epithelial_reclustered <- readRDS("/scratch/hnatri/ILD/ILD_spatial_ASE/epithelial_reclustered.rds")

# Dimplot of clusters
DimPlot(epithelial_reclustered,
        group.by = "snn_res.0.3",
        cols = cluster_col,
        reduction = "umap",
        raster = T,
        label = T) +
  coord_fixed(ratio = 1) +
  NoLegend() +
  theme_minimal()
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`

# Cell type markers
DotPlot(epithelial_reclustered,
        features = unique(c(epithelial_features,
                            immune_features,
                            endothelial_features,
                            mesenchymal_features)),
        group.by = "snn_res.0.3",
        cols = c("azure", "tomato3")) +
  coord_flip() +
  theme_minimal()
Warning: The following requested variables were not found (10 out of 126
shown): NKX2-1, RTKN2, NAPSA, PGC, SFTPC, KRT14, KRT5, KRT6A, S100A2, KRT17

FeaturePlot(epithelial_reclustered,
            features = epithelial_features,
            ncol = 3,
            reduction = "umap",
            raster = T,
            cols = c("gray89", "tomato3")) &
  coord_fixed(ratio = 1) &
  NoLegend() &
  theme_minimal()
Warning: The following requested variables were not found (10 out of 38 shown):
NKX2-1, RTKN2, NAPSA, PGC, SFTPC, KRT14, KRT5, KRT6A, S100A2, KRT17
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`

FeaturePlot(epithelial_reclustered,
            features = immune_features,
            ncol = 3,
            reduction = "umap",
            raster = T,
            cols = c("gray89", "tomato3")) &
  coord_fixed(ratio = 1) &
  NoLegend() &
  theme_minimal()
Warning: The following requested variables were not found (10 out of 35 shown):
PPARG, LTB, HLA-DRA, CXCR4, PTPRC, CD69, CD3G, TRAC, ITM2C, CCL5
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`

FeaturePlot(epithelial_reclustered,
            features = endothelial_features,
            ncol = 3,
            reduction = "umap",
            raster = T,
            cols = c("gray89", "tomato3")) &
  coord_fixed(ratio = 1) &
  NoLegend() &
  theme_minimal()
Warning: The following requested variables were not found (10 out of 23 shown):
APLN, HEY1, BMPR2, EPAS1, PECAM1, APLNR, COL15A1, POSTN, ZEB1, HAS1
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`

FeaturePlot(epithelial_reclustered,
            features = mesenchymal_features,
            ncol = 3,
            reduction = "umap",
            raster = T,
            cols = c("gray89", "tomato3")) &
  coord_fixed(ratio = 1) &
  NoLegend() &
  theme_minimal()
Warning: The following requested variables were not found (10 out of 30 shown):
PI16, ELN, FAP, AXL, COL1A1, COL1A2, COL3A1, DCN, FN1, HAS2
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`

Some clusters are not epithelial:
* Cluster 3: endothelial
* Clusters 0, 4, 5, 6, 8, 9, 10: immune

Adding lineage to the metadata

epithelial_reclustered$lineage <- ifelse(epithelial_reclustered$snn_res.0.3 %in% c(1, 2), "Epithelial",
                                  ifelse(epithelial_reclustered$snn_res.0.3 %in% c(3), "Endothelial",
                                  ifelse(epithelial_reclustered$snn_res.0.3 %in% c(0, 4, 5, 6, 7, 8, 9, 10), "Immune", NA)))

#saveRDS(epithelial_reclustered, "/scratch/hnatri/ILD/ILD_spatial_ASE/epithelial_reclustered.rds")

Immune

Subsetting clusters with immune marker expression and reclustering

immune <- subset(seurat_object, subset = leiden_res0.5 %in% imm_clusters)

# Saving the object for clustering with scanpy
#saveRDS(epithelial, "/scratch/hnatri/ILD/ILD_spatial_ASE/epithelial.rds")
#epithelial <- readRDS("/scratch/hnatri/ILD/ILD_spatial_ASE/epithelial_clustered.rds")

# Reclustering using Seurat. The function is sourced from /code/utilities.R
immune_reclustered <- recluster(immune)
# PCs for UMAP: 9
Found more than one class "dist" in cache; using the first, from namespace 'spam'
Also defined by 'BiocGenerics'
Found more than one class "dist" in cache; using the first, from namespace 'spam'
Also defined by 'BiocGenerics'
#saveRDS(immune_reclustered, "/scratch/hnatri/ILD/ILD_spatial_ASE/immune_reclustered.rds")

Marker expression

#immune_reclustered <- readRDS("/scratch/hnatri/ILD/ILD_spatial_ASE/immune_reclustered.rds")

# Dimplot of clusters
DimPlot(immune_reclustered,
        group.by = "snn_res.0.3",
        cols = cluster_col,
        reduction = "umap",
        raster = T,
        label = T) +
  coord_fixed(ratio = 1) +
  NoLegend() +
  theme_minimal()

# Cell type markers
DotPlot(immune_reclustered,
        features = unique(c(epithelial_features,
                            immune_features,
                            endothelial_features,
                            mesenchymal_features)),
        group.by = "snn_res.0.3",
        cols = c("azure", "tomato3")) +
  coord_flip() +
  theme_minimal()
Warning: The following requested variables were not found (10 out of 126
shown): NKX2-1, RTKN2, NAPSA, PGC, SFTPC, KRT14, KRT5, KRT6A, S100A2, KRT17

FeaturePlot(immune_reclustered,
            features = epithelial_features,
            ncol = 3,
            reduction = "umap",
            raster = T,
            cols = c("gray89", "tomato3")) &
  coord_fixed(ratio = 1) &
  NoLegend() &
  theme_minimal()
Warning: The following requested variables were not found (10 out of 38 shown):
NKX2-1, RTKN2, NAPSA, PGC, SFTPC, KRT14, KRT5, KRT6A, S100A2, KRT17

FeaturePlot(immune_reclustered,
            features = immune_features,
            ncol = 3,
            reduction = "umap",
            raster = T,
            cols = c("gray89", "tomato3")) &
  coord_fixed(ratio = 1) &
  NoLegend() &
  theme_minimal()
Warning: The following requested variables were not found (10 out of 35 shown):
PPARG, LTB, HLA-DRA, CXCR4, PTPRC, CD69, CD3G, TRAC, ITM2C, CCL5

FeaturePlot(immune_reclustered,
            features = endothelial_features,
            ncol = 3,
            reduction = "umap",
            raster = T,
            cols = c("gray89", "tomato3")) &
  coord_fixed(ratio = 1) &
  NoLegend() &
  theme_minimal()
Warning: The following requested variables were not found (10 out of 23 shown):
APLN, HEY1, BMPR2, EPAS1, PECAM1, APLNR, COL15A1, POSTN, ZEB1, HAS1

FeaturePlot(immune_reclustered,
            features = mesenchymal_features,
            ncol = 3,
            reduction = "umap",
            raster = T,
            cols = c("gray89", "tomato3")) &
  coord_fixed(ratio = 1) &
  NoLegend() &
  theme_minimal()
Warning: The following requested variables were not found (10 out of 30 shown):
PI16, ELN, FAP, AXL, COL1A1, COL1A2, COL3A1, DCN, FN1, HAS2

Some clusters are not immune: * Cluster 5: epithelial * Clusters 3, 4: endothelial * Clusters

Adding lineage to the metadata

immune_reclustered$lineage <- ifelse(immune_reclustered$snn_res.0.3 %in% c(5), "Epithelial",
                              ifelse(immune_reclustered$snn_res.0.3 %in% c(3, 4), "Endothelial",
                              ifelse(immune_reclustered$snn_res.0.3 %in% c(0, 1, 2, 6, 7, 8), "Immune", NA)))

#saveRDS(immune_reclustered, "/scratch/hnatri/ILD/ILD_spatial_ASE/immune_reclustered.rds")

Endothelial and mesenchymal

Subsetting and reclustering

endo_mesen <- subset(seurat_object, subset = leiden_res0.5 %in% endo_mesen_clusters)

# Saving the object for clustering with scanpy
#saveRDS(epithelial, "/scratch/hnatri/ILD/ILD_spatial_ASE/epithelial.rds")
#epithelial <- readRDS("/scratch/hnatri/ILD/ILD_spatial_ASE/epithelial_clustered.rds")

# Reclustering using Seurat. The function is sourced from /code/utilities.R
endo_mesen_reclustered <- recluster(endo_mesen)
# PCs for UMAP: 10
Found more than one class "dist" in cache; using the first, from namespace 'spam'
Also defined by 'BiocGenerics'
Found more than one class "dist" in cache; using the first, from namespace 'spam'
Also defined by 'BiocGenerics'
#saveRDS(endo_mesen_reclustered, "/scratch/hnatri/ILD/ILD_spatial_ASE/endo_mesen_reclustered.rds")

Marker expression

#endo_mesen_reclustered <- readRDS("/scratch/hnatri/ILD/ILD_spatial_ASE/endo_mesen_reclustered.rds")

# Dimplot of clusters
DimPlot(endo_mesen_reclustered,
        group.by = "snn_res.0.3",
        cols = cluster_col,
        reduction = "umap",
        raster = T,
        label = T) +
  coord_fixed(ratio = 1) +
  NoLegend() +
  theme_minimal()
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`

# Cell type markers
DotPlot(endo_mesen_reclustered,
        features = unique(c(epithelial_features,
                            immune_features,
                            endothelial_features,
                            mesenchymal_features)),
        group.by = "snn_res.0.3",
        cols = c("azure", "tomato3")) +
  coord_flip() +
  theme_minimal()
Warning: The following requested variables were not found (10 out of 126
shown): NKX2-1, RTKN2, NAPSA, PGC, SFTPC, KRT14, KRT5, KRT6A, S100A2, KRT17

FeaturePlot(endo_mesen_reclustered,
            features = epithelial_features,
            ncol = 3,
            reduction = "umap",
            raster = T,
            cols = c("gray89", "tomato3")) &
  coord_fixed(ratio = 1) &
  NoLegend() &
  theme_minimal()
Warning: The following requested variables were not found (10 out of 38 shown):
NKX2-1, RTKN2, NAPSA, PGC, SFTPC, KRT14, KRT5, KRT6A, S100A2, KRT17
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`

FeaturePlot(endo_mesen_reclustered,
            features = immune_features,
            ncol = 3,
            reduction = "umap",
            raster = T,
            cols = c("gray89", "tomato3")) &
  coord_fixed(ratio = 1) &
  NoLegend() &
  theme_minimal()
Warning: The following requested variables were not found (10 out of 35 shown):
PPARG, LTB, HLA-DRA, CXCR4, PTPRC, CD69, CD3G, TRAC, ITM2C, CCL5
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`

FeaturePlot(endo_mesen_reclustered,
            features = endothelial_features,
            ncol = 3,
            reduction = "umap",
            raster = T,
            cols = c("gray89", "tomato3")) &
  coord_fixed(ratio = 1) &
  NoLegend() &
  theme_minimal()
Warning: The following requested variables were not found (10 out of 23 shown):
APLN, HEY1, BMPR2, EPAS1, PECAM1, APLNR, COL15A1, POSTN, ZEB1, HAS1
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`

FeaturePlot(endo_mesen_reclustered,
            features = mesenchymal_features,
            ncol = 3,
            reduction = "umap",
            raster = T,
            cols = c("gray89", "tomato3")) &
  coord_fixed(ratio = 1) &
  NoLegend() &
  theme_minimal()
Warning: The following requested variables were not found (10 out of 30 shown):
PI16, ELN, FAP, AXL, COL1A1, COL1A2, COL3A1, DCN, FN1, HAS2
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`
Rasterizing points since number of points exceeds 100,000.
To disable this behavior set `raster=FALSE`

Some clusters are not endothelial/mesenchymal:
* Cluster 0: epithelial
* Cluster 2, 4, 6, 7: immune

Adding lineage to the metadata

endo_mesen_reclustered$lineage <- ifelse(endo_mesen_reclustered$snn_res.0.3 %in% c(0), "Epithelial",
                                  ifelse(endo_mesen_reclustered$snn_res.0.3 %in% c(2, 4, 6, 7), "Immune", "Endo_Mesen"))

#saveRDS(endo_mesen_reclustered, "/scratch/hnatri/ILD/ILD_spatial_ASE/endo_mesen_reclustered.rds")

Subsetting and merging at the lineage level

unique(epithelial_reclustered$lineage)
[1] "Immune"      "Endothelial" "Epithelial" 
unique(immune_reclustered$lineage)
[1] "Immune"      "Endothelial" "Epithelial" 
unique(endo_mesen_reclustered$lineage)
[1] "Immune"     "Endo_Mesen" "Epithelial"
epithelial_subsets <- list("epi1" = subset(epithelial_reclustered, subset = lineage == "Epithelial"),
                           "epi2" = subset(immune_reclustered, subset = lineage == "Epithelial"),
                           "epi3" = subset(endo_mesen_reclustered, subset = lineage == "Epithelial"))

immune_subsets <- list("imm1" = subset(epithelial_reclustered, subset = lineage == "Immune"),
                       "imm2" = subset(immune_reclustered, subset = lineage == "Immune"),
                       "imm3" = subset(endo_mesen_reclustered, subset = lineage == "Immune"))

endo_mesen_subsets <- list("em1" = subset(epithelial_reclustered, subset = lineage %in% c("Endo_Mesen", "Endothelial")),
                           "em2" = subset(immune_reclustered, subset = lineage %in% c("Endo_Mesen", "Endothelial")),
                           "em3" = subset(endo_mesen_reclustered, subset = lineage %in% c("Endo_Mesen", "Endothelial")))

epithelial_merged <- merge(x = epithelial_subsets[[1]],
                           y = epithelial_subsets[2:length(epithelial_subsets)])
immune_merged <- merge(x = immune_subsets[[1]],
                       y = immune_subsets[2:length(immune_subsets)])
endo_mesen_merged <- merge(x = endo_mesen_subsets[[1]],
                           y = endo_mesen_subsets[2:length(endo_mesen_subsets)])

# Saving
#saveRDS(epithelial_merged, "/scratch/hnatri/ILD/ILD_spatial_ASE/epithelial_merged.rds")
#saveRDS(immune_merged, "/scratch/hnatri/ILD/ILD_spatial_ASE/immune_merged.rds")
#saveRDS(endo_mesen_merged, "/scratch/hnatri/ILD/ILD_spatial_ASE/endo_mesen_merged.rds")

sessionInfo()
R version 4.3.0 (2023-04-21)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.2 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so;  LAPACK version 3.10.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

time zone: Etc/UTC
tzcode source: system (glibc)

attached base packages:
[1] grid      stats     graphics  grDevices utils     datasets  methods  
[8] base     

other attached packages:
 [1] ComplexHeatmap_2.16.0   RColorBrewer_1.1-3      viridis_0.6.3          
 [4] viridisLite_0.4.2       ggthemes_5.0.0          googlesheets4_1.1.0    
 [7] workflowr_1.7.1         ggrepel_0.9.3           ggpubr_0.6.0           
[10] lubridate_1.9.2         forcats_1.0.0           stringr_1.5.0          
[13] dplyr_1.1.2             purrr_1.0.1             readr_2.1.4            
[16] tidyr_1.3.0             tibble_3.2.1            ggplot2_3.4.2          
[19] tidyverse_2.0.0         SeuratDisk_0.0.0.9021   Seurat_4.9.9.9048      
[22] SeuratObject_4.9.9.9084 sp_1.6-1                cli_3.6.1              

loaded via a namespace (and not attached):
  [1] RcppAnnoy_0.0.20       splines_4.3.0          later_1.3.1           
  [4] cellranger_1.1.0       polyclip_1.10-4        fastDummies_1.6.3     
  [7] lifecycle_1.0.3        rstatix_0.7.2          doParallel_1.0.17     
 [10] rprojroot_2.0.3        globals_0.16.2         processx_3.8.1        
 [13] lattice_0.21-8         hdf5r_1.3.8            MASS_7.3-60           
 [16] backports_1.4.1        magrittr_2.0.3         plotly_4.10.2         
 [19] sass_0.4.6             rmarkdown_2.22         jquerylib_0.1.4       
 [22] yaml_2.3.7             httpuv_1.6.11          sctransform_0.3.5     
 [25] spam_2.9-1             spatstat.sparse_3.0-1  reticulate_1.29       
 [28] cowplot_1.1.1          pbapply_1.7-0          abind_1.4-5           
 [31] Rtsne_0.16             BiocGenerics_0.46.0    git2r_0.32.0          
 [34] circlize_0.4.15        S4Vectors_0.38.1       IRanges_2.34.0        
 [37] irlba_2.3.5.1          listenv_0.9.0          spatstat.utils_3.0-3  
 [40] goftest_1.2-3          RSpectra_0.16-1        spatstat.random_3.1-5 
 [43] fitdistrplus_1.1-11    parallelly_1.36.0      leiden_0.4.3          
 [46] codetools_0.2-19       shape_1.4.6            tidyselect_1.2.0      
 [49] farver_2.1.1           stats4_4.3.0           matrixStats_1.0.0     
 [52] spatstat.explore_3.2-1 googledrive_2.1.0      jsonlite_1.8.5        
 [55] GetoptLong_1.0.5       ellipsis_0.3.2         progressr_0.13.0      
 [58] iterators_1.0.14       ggridges_0.5.4         survival_3.5-5        
 [61] foreach_1.5.2          tools_4.3.0            ica_1.0-3             
 [64] Rcpp_1.0.10            glue_1.6.2             gridExtra_2.3         
 [67] xfun_0.39              withr_2.5.0            fastmap_1.1.1         
 [70] fansi_1.0.4            callr_3.7.3            digest_0.6.31         
 [73] timechange_0.2.0       R6_2.5.1               mime_0.12             
 [76] colorspace_2.1-0       scattermore_1.1        tensor_1.5            
 [79] spatstat.data_3.0-1    utf8_1.2.3             generics_0.1.3        
 [82] data.table_1.14.8      httr_1.4.6             htmlwidgets_1.6.2     
 [85] whisker_0.4.1          uwot_0.1.14            pkgconfig_2.0.3       
 [88] gtable_0.3.3           lmtest_0.9-40          htmltools_0.5.5       
 [91] carData_3.0-5          dotCall64_1.0-2        clue_0.3-64           
 [94] scales_1.2.1           png_0.1-8              knitr_1.43            
 [97] rstudioapi_0.14        rjson_0.2.21           tzdb_0.4.0            
[100] reshape2_1.4.4         nlme_3.1-162           curl_5.0.0            
[103] GlobalOptions_0.1.2    cachem_1.0.8           zoo_1.8-12            
[106] KernSmooth_2.23-21     parallel_4.3.0         miniUI_0.1.1.1        
[109] pillar_1.9.0           vctrs_0.6.2            RANN_2.6.1            
[112] promises_1.2.0.1       car_3.1-2              xtable_1.8-4          
[115] cluster_2.1.4          evaluate_0.21          compiler_4.3.0        
[118] rlang_1.1.1            crayon_1.5.2           future.apply_1.11.0   
[121] ggsignif_0.6.4         labeling_0.4.2         ps_1.7.5              
[124] getPass_0.2-2          plyr_1.8.8             fs_1.6.2              
[127] stringi_1.7.12         deldir_1.0-9           munsell_0.5.0         
[130] lazyeval_0.2.2         spatstat.geom_3.2-1    Matrix_1.5-4.1        
[133] RcppHNSW_0.4.1         hms_1.1.3              patchwork_1.1.2       
[136] bit64_4.0.5            future_1.32.0          shiny_1.7.4           
[139] highr_0.10             ROCR_1.0-11            gargle_1.4.0          
[142] igraph_1.4.3           broom_1.0.4            bslib_0.4.2           
[145] bit_4.0.5